/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wli.web.java.db;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author wli
 */
public class WordHelper {

    Session session = null;

    public WordHelper() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public List getWordList() {
        List<Word> wordList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Word");
            wordList = (List<Word>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return wordList;
    }
    
     public Word getWordById(int wid) {
        System.out.println("WordHelper===========getWordById========       ID="+wid+"      =========");
        Word wd = null;

        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = null;
            
             if (wid <= 0) {
                q = session.createQuery("from Word");
            } else {
                q = session.createQuery("from Word as wd where wd.word_id="+wid);
            }
          
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>AAAAAAAAAAAAAAAAAAA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+q.list());
            wd = (Word) q.list().get(0);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return wd;
    }
}
